<template>
  <!-- 消息更多 -->
  <div class="page_padding">
    <MyNavBar @goback="goback" @clear="onClear" :title="title" :clear="isClear" />
    <write-notification-list ref="list" :type="type" v-if="notifyArr.includes(type)"></write-notification-list>
    <system-notification-list ref="list" :type="type" v-else></system-notification-list>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import MyNavBar from '@com/MyNavBar'
import writeNotificationList from './components/writeNotificationList'
import systemNotificationList from './components/systemNotificationList.vue'
import { updateAllNoticeRead } from '@api/api.js'
export default {
  name: 'MessageList',
  components: { MyNavBar, writeNotificationList, systemNotificationList },
  props: {},
  data() {
    return {
      titleEmpty: '纪实通知',
      title: '纪实通知',
      workList: [],
      currentPage: 1,
      pageSize: 20,
      workTotalPages: 0,
      loading: false,
      finished: false,
      type: 'SYSTEM_NOTICE',
      isClear: false,
      unReadNum: '',
      notifyArr: [
        '01',
        '03',
        'USER_STATUS_CHANGE',
        'ORG_MODIFY_RANK',
        'PEOPLE_ASSESS',
        'rckq',
        'meetingManage',
        'PEOPLE_ASSESS_CHECK',
        'TASK_NOTICE_V2',
      ],
    }
  },
  computed: {
    ...mapGetters(['messageOneNum']),
  },
  watch: {
    messageOneNum: {
      handler(news) {
        this.unReadNum = news
        if (this.unReadNum > 0) {
          this.isClear = true
          this.title = this.titleEmpty + '(' + this.unReadNum + ')'
        } else {
          this.isClear = false
          this.title = this.titleEmpty
        }
      },
      deep: true,
    },
  },
  created() {
    this.type = this.$route.query.id
    this.unReadNum = this.messageOneNum
    this.titleEmpty = this.$route.query.name
    if (this.unReadNum > 0) {
      this.isClear = true
      this.title = this.titleEmpty + '(' + this.unReadNum + ')'
    } else {
      this.isClear = false
      this.title = this.titleEmpty
    }
  },
  mounted() {},
  methods: {
    goback() {
      this.$router.go(-1)
    },
    onClear() {
      updateAllNoticeRead({ oneParam: this.type }).then(res => {
        this.$refs.list.clear()
        this.$store.commit('setMessageOneNum', 0)
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
